package mest.controller.Modeling;

import com.alibaba.fastjson.JSON;
import mest.entity.apart_file;
import mest.entity.employee_file;
import mest.service.Modeling.IapartFileService;
import mest.service.Modeling.IemployeeFileService;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Description
 * @auther Machenike
 * @create 2019-11-15 22:41
 */
@RestController
@CrossOrigin
@RequestMapping(value = "/employeeFile")
public class employeeFile {

    @Resource
    private IemployeeFileService iefs;

    @RequestMapping(value="/insert")
    public String insert(employee_file ef , String date){

        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Date dateTime = null;
        try {
            dateTime = simpleDateFormat.parse(date);
        } catch (ParseException e) {
            e.printStackTrace();
        }

        ef.setEmployeeDate(dateTime);

        int i = iefs.insertEmployeeFile(ef);
        if (i >= 1)
            return JSON.toJSONString("添加成功");
        else
            return JSON.toJSONString("添加失败");
    }
    @RequestMapping(value = "/baseSelect", produces = {"application/json;charset=utf-8", "text/plain;charset=utf-8"})
    public String baseSelect(int index,int pageSize) {

        List<employee_file> employeeFilePage = iefs.findEmployeeFilePage(index, pageSize);
        int i = iefs.selectCount();
        Map map  = new HashMap();
        map.put("code",0);
        map.put("msg","");
        map.put("count",i);
        map.put("data",employeeFilePage);
        return JSON.toJSONString(map);
    }


    @RequestMapping(value="/a")
    public String a(){
        return "aaaa";
    }
}
